package com.jrh.dal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jrh.domain.entity.Resource;

/**
 * 资源信息DAO
 * 
 * @author jasen.hsu.cn@gmail.com 2012-7-17 下午2:23:47
 */
public class ResourceDao extends BaseDao<Resource> {

    public ResourceDao(){
        this.namespace = "jrh.single.resource";
    }

    /**
     * 根据key和group删除资源信息
     * 
     * @param rkey
     * @param rgroup
     */
    public void deleteByKeyAndGroup(String rkey, String rgroup) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("rkey", rkey);
        map.put("rgroup", rgroup);
        sqlMapClientTemplate.delete(namespace + "." + "delete", map);
    }

    /**
     * 根据key和group取得资源信息
     * 
     * @param rkey
     * @param rgroup
     * @return
     */
    public Resource loadByKeyAndGroup(String rkey, String rgroup) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("rkey", rkey);
        map.put("rgroup", rgroup);
        return (Resource) sqlMapClientTemplate.queryForObject(namespace + "." + "loadByKeyAndGroup", map);
    }

    /**
     * 根据组取得资源信息列表
     * 
     * @param rgroup
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<Resource> listByGroup(String rgroup) {
        return (List<Resource>) sqlMapClientTemplate.queryForList(namespace + "." + "listByGroup", rgroup);
    }

    /**
     * 取得所有资源信息列表
     * 
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<Resource> listAll() {
        return (List<Resource>) sqlMapClientTemplate.queryForList(namespace + "." + "listAllResource");
    }

    /**
     * 根据key和group更新资源信息value
     * 
     * @param rkey
     * @param rgroup
     */
    public boolean updateByKeyAndGroup(String rkey, String rgroup, String rvalue) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("rkey", rkey);
        map.put("rgroup", rgroup);
        map.put("rvalue", rvalue);
        return sqlMapClientTemplate.update(namespace + "." + "update", map) == 1;
    }

}
